﻿<UserControl x:Class="BizControl.Presentation.ActivityEditModule.Views.DependentActivitiesView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:converters="clr-namespace:BizControl.Presentation.ActivityEditModule.Converters">

    <UserControl.Resources>
        <converters:ParentOrPreviousActivityToTextConverter x:Key="ParentOrPreviousActivityToTextConverter" />
        <converters:ParentOrPreviousActivityToVisibilityConverter x:Key="ParentOrPreviousActivityToVisibilityConverter" />
        <converters:ParentOrPreviousActivityToActivityConverter x:Key="ParentOrPreviousActivityToActivityConverter" />
    </UserControl.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="60" />
            <RowDefinition Height="30" />
            <RowDefinition />
            <RowDefinition />
        </Grid.RowDefinitions>
        <StackPanel>
            <StackPanel.Visibility>
                <MultiBinding Converter="{StaticResource ParentOrPreviousActivityToVisibilityConverter}">
                    <Binding Path="Activity.HasParentActivity" />
                    <Binding Path="Activity.HasPreviousActivity" />
                </MultiBinding>
            </StackPanel.Visibility>
            <TextBlock VerticalAlignment="Center" FontWeight="Bold">
                <TextBlock.Text>
                    <MultiBinding Converter="{StaticResource ParentOrPreviousActivityToTextConverter}">
                        <Binding Path="Activity.HasParentActivity" />
                        <Binding Path="Activity.HasPreviousActivity" />
                    </MultiBinding>
                </TextBlock.Text>
            </TextBlock>
            <Border BorderThickness="0,0,0,1" BorderBrush="{StaticResource BorderLightBrush}" />

            <StackPanel VerticalAlignment="Center" Orientation="Horizontal">
                <StackPanel.DataContext>
                    <MultiBinding Converter="{StaticResource ParentOrPreviousActivityToActivityConverter}">
                        <Binding Path="Activity.HasParentActivity" />
                        <Binding Path="Activity.HasPreviousActivity" />
                        <Binding Path="Activity.ParentActivity" />
                        <Binding Path="Activity.PreviousActivity" />
                    </MultiBinding>
                </StackPanel.DataContext>
                <TextBlock HorizontalAlignment="Left" VerticalAlignment="Center" Margin="2">
                    <Hyperlink><!-- Command="{Binding Path=NavigateToActivityCommand}"
                               CommandParameter="{Binding Path=Id}">-->
                        <TextBlock Text="{Binding Path=ShortenDescription}" />
                    </Hyperlink>
                </TextBlock>
                <ProgressBar Style="{StaticResource ProgressBarWithText}" Grid.Column="2" Height="20" Margin="2" Width="140" 
                             VerticalAlignment="Center" HorizontalAlignment="Center"
                             ToolTip="Прогресс задачи"
                             Value="{Binding Path=Progress, Mode=OneWay}" />
            </StackPanel>
            <Border BorderThickness="0,0,0,1" BorderBrush="{StaticResource SolidBorderBrush}" />
        </StackPanel>
        <Grid Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <TextBlock Margin="2" FontWeight="Bold" Text="Дочерние задачи" />
            <TextBlock Grid.Column="1" Margin="2" FontWeight="Bold" Text="Следующие задачи" />
            <Border Grid.ColumnSpan="2" BorderThickness="0,0,0,1" BorderBrush="{StaticResource SolidBorderBrush}" />
        </Grid>
        <Grid Grid.Row="2">
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <ListBox Margin="5"
                     Style="{StaticResource DefaultListBoxStyle}" ItemsSource="{Binding Path=Activity.ChildActivities}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock TextWrapping="Wrap" Width="250"
                                       HorizontalAlignment="Left" VerticalAlignment="Center" Margin="2">
                                <Hyperlink>
                                    <Run Text="{Binding Path=ShortenDescription, Mode=OneWay}" />
                                </Hyperlink>
                            </TextBlock>
                            <ProgressBar Style="{StaticResource ProgressBarWithText}" Grid.Column="2" Height="20" Margin="2" Width="140" 
                                         VerticalAlignment="Center" HorizontalAlignment="Right"
                                         ToolTip="Прогресс задачи"
                                         Value="{Binding Path=Progress, Mode=OneWay}" />
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
            <ListBox Grid.Column="1" Margin="5"
                     Style="{StaticResource DefaultListBoxStyle}" ItemsSource="{Binding Path=Activity.NextActivities}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock TextWrapping="Wrap" Width="250"
                                       HorizontalAlignment="Left" VerticalAlignment="Center" Margin="2">
                                <Hyperlink>
                                    <Run Text="{Binding Path=ShortenDescription, Mode=OneWay}" />
                                </Hyperlink>
                            </TextBlock>
                            <ProgressBar Style="{StaticResource ProgressBarWithText}" Grid.Column="2" Height="20" Margin="2" Width="140" 
                                         VerticalAlignment="Center" HorizontalAlignment="Right"
                                         ToolTip="Прогресс задачи"
                                         Value="{Binding Path=Progress, Mode=OneWay}" />
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </Grid>
        <Border Grid.Row="2" BorderThickness="0,0,0,1" BorderBrush="{StaticResource SolidBorderBrush}" />
        <Grid Grid.Row="3">
            <Grid.RowDefinitions>
                <RowDefinition Height="30" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <StackPanel Orientation="Horizontal">
                <StackPanel Orientation="Horizontal">
                    <TextBlock HorizontalAlignment="Left" VerticalAlignment="Center" Margin="2">
                        <Hyperlink Command="{Binding Path=AddChildLinkCommand}">
                            <TextBlock Text="Сделать дочерней" />
                        </Hyperlink>
                    </TextBlock>
                    <Border BorderThickness="1" BorderBrush="{StaticResource SolidBorderBrush}" />
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                    <TextBlock HorizontalAlignment="Left" VerticalAlignment="Center" Margin="2">
                        <Hyperlink Command="{Binding Path=AddNextLinkCommand}">
                            <TextBlock Text="Сделать следующей" />
                        </Hyperlink>
                    </TextBlock>
                    <Border BorderThickness="1" BorderBrush="{StaticResource SolidBorderBrush}" />
                </StackPanel>
            </StackPanel>
            <Border BorderThickness="0,0,0,1" BorderBrush="{StaticResource SolidBorderBrush}" />
            <ComboBox Grid.Row="1" Width="250" Margin="2"
                      Height="60" VerticalAlignment="Top" HorizontalAlignment="Left"
                      ItemsSource="{Binding Path=IndependentActivities}"
                      SelectedValue="{Binding Path=SelectedActivity, Mode=TwoWay}">
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock TextWrapping="Wrap" Width="250" Text="{Binding Path=ShortenDescription, Mode=OneWay}"
                                       HorizontalAlignment="Left" VerticalAlignment="Center" Margin="2" />
                            <ProgressBar Style="{StaticResource ProgressBarWithText}" Grid.Column="2" Height="20" Margin="2" Width="140" 
                                         VerticalAlignment="Center" HorizontalAlignment="Right"
                                         ToolTip="Прогресс задачи"
                                         Value="{Binding Path=Progress, Mode=OneWay}" />
                        </StackPanel>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>
        </Grid>

        <!-- add child / next -->
    </Grid>
</UserControl>
